'''
Created on Jun 14, 2009

@author: trevor
'''

import random,copy,math

class TravSales(object):
    
    def __init__(self):
        self.OrderedList = dict()
        self.num = 1000
        for i in range (0,self.num):
            self.OrderedList[i] = ((random.random()*500) , (random.random()*500))
            

def Creator():
    #return an initial instance of the class
    return TravSales()

def Mutator(obj):
    #return a neighbor of this class
    temp = copy.deepcopy(obj)
    
    index = random.randint(0,obj.num-1)
    index2 = random.randint(0,obj.num-1)
    while(index == index2):
        index2 = random.randint(0,obj.num-1)
    tempCity = temp.OrderedList[index]
    temp.OrderedList[index] = obj.OrderedList[index2]
    temp.OrderedList[index2] = temp.OrderedList[index]
    return temp
    
def Printable(obj):
    #be able to print out the class
    runningTotal = 0
    x1 = (obj.OrderedList[obj.num-1])[0] #Start with the very last city
    y1 = (obj.OrderedList[obj.num-1])[1]
    for i in range(0,100):
        x2 = (obj.OrderedList[i])[0]  
        y2 = (obj.OrderedList[i])[1]
            
        d = math.sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) )  #and compute the distance between (x1,y1) and (x2,y2)
        runningTotal = runningTotal + d
            
        x1 = x2
        y1 = y2
        
    return runningTotal

def Comparor(obj_one, obj_two):
    #determine if obj_one is BETTER than obj_two
    if Printable(obj_one) < Printable(obj_two):
        return True
    else:
        return False
    
def Differencer(obj_one, obj_two):
    #if obj_one is better, return a -1, if obj_two is better, return a 1
    #this assumes we're trying to minimize a value.  Reverse it for maximizing 
    if Printable(obj_one) < Printable(obj_two):
        return -1
    else:
        return 1